import OceanComponent from './OceanComponent';
import ODialog from '../../components/Dialog.vue';
import useModal from '../../hooks/useModal';
import { ButtonProps } from 'naive-ui';
import Buttons, { TButtonProps } from './Button';

type TButton = ButtonProps['type'];

type TDialogProps = {
  title: string;
  width?: string | number;
  component?: Function;
  action?: Function;
} & __Object;

interface IDialog {
  open(a);
  close();
  button(name: string, props: TButtonProps);
}

class Dialog extends OceanComponent<TDialogProps> implements IDialog {
  modal = useModal();
  buttons: Buttons = new Buttons();
  componentAttrs: any;
  component: __VueComponent;
  constructor(title: string, component?: __VueComponent) {
    super(ODialog, { title });
    this.component = typeof component == 'function' ? component : () => component;
  }
  open(componentAttrs?): void {
    this.componentAttrs = componentAttrs;
    this.modal.open();
  }
  close(): void {
    this.modal.close();
  }
  button(name: string, props?: TButtonProps) {
    return this.buttons.button(name, props);
  }
  setTitle(title: string) {
    this.attrs.title = title;
    return this;
  }
}
export default Dialog;
export type { TDialogProps };
